package com.generator.base;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;

/**
 * Created by pichun on 2016-10-12.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class OutputObj<T> {

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @ApiModelProperty(value = "业务状态码，0成功，1失败")
    private String status;

    @ApiModelProperty(value = "返回信息")
    private String msg;

    @ApiModelProperty(value = "返回详细数据")
    private T data;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public OutputObj() {
    }

    public static <T> OutputObj<T> success() {
        return new OutputObj<>(Result.SUCCEE.getCode(), Result.SUCCEE.getMsg(), null);
    }

    public static <T> OutputObj<T> success(T data) {
        return new OutputObj<>(Result.SUCCEE.getCode(), Result.SUCCEE.getMsg(), data);
    }
    public static <T> OutputObj<T> success(String msg) {
        return new OutputObj<>(Result.SUCCEE.getCode(), msg, null);
    }
    public static <T>  OutputObj<T> success(T data, String msg) {
        return new  OutputObj<>(Result.SUCCEE.getCode(), msg, data);
    }

    public static <T> OutputObj<T> fail(String msg) {
        return new OutputObj<>(Result.FAIL.getCode(), msg, null);
    }

    /**
     * 创建一个新的实例 OutputObj.
     */

    public OutputObj(String status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public OutputObj(String status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public enum Result {

        SUCCEE("0", "访问成功"), FAIL("1", "访问失败");

        public String getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }

        private String code;
        private String msg;

        private Result(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }
    }

}
